package mil.af.amc.adpetracker.service;

import mil.af.amc.adpetracker.dao.OrganizationDao;
import mil.af.amc.adpetracker.model.Organization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Please Fill in this Javadoc
 *
 * @author TSgt Jason Ferguson
 */
@Service("organizationService")
public class OrganizationServiceImpl implements OrganizationService {

    private OrganizationDao organizationDao;

    @Autowired
    public void setOrganizationDao(OrganizationDao organizationDao) {
        this.organizationDao = organizationDao;
    }

    public Organization getById(int id) {

        return organizationDao.getById(id);
    }

    public List<Organization> getAll() {

        return organizationDao.getAll();
    }


    public Organization add(Map organizationMap) {

        Organization org = new Organization();
        org.setName((String) organizationMap.get("name"));

        int parentId = (Integer) organizationMap.get("parent");
        Organization parent = organizationDao.getById(parentId);
        org.setParent(parent);

        int orgId = organizationDao.add(org);
        org.setId(orgId);
        return org;
    }
}
